﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class adm_vlg_categoryEdit : System.Web.UI.Page
{
    VLGDataContext _db8 = new VLGDataContext();
    Category category = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session["AID"] == null)
        //    Response.Redirect("login.aspx");
        if (IsPostBack) return;

        //if (!FUNCTION.CheckAmin())
        //{
        //    Panel_admin.Visible = false;
        //    Panel_avatar.Visible = false;
        //    Panel_Meta.Visible = false;
        //    Panel_trong.Visible = false;
        //}

        if (Request.QueryString["action"] == "edit")
        {
            ltr_action_name.Text = "Sửa chữa";
            category = _db8.Categories.Select(cat => cat).Where(cat => cat.idCategory == Convert.ToInt32(Request.QueryString["id"])).FirstOrDefault();



        }
        else
        {

            ltr_action_name.Text = "Thêm mới";
        }
        FillData();
    }
    public void FillData()
    {
        if (category != null)
        {
            txtTenCate.Text = category.TenCate;
           // txtTenCate_E.Text = category.TenCate_E;
            txtThuTu.Text = category.ThuTu.ToString();
            //chkAnHien.Checked = (bool)category.AnHien;
            // chkAnHien.Text = category.AnHien == true ? "Hiên" : "Ẩn";
        }
    }
    protected void butt_save_Click(object sender, EventArgs e)
    {
        if (category == null)
            category = new Category();
        if (Request.QueryString["action"] == "edit")
        {
            category = _db8.Categories.Select(cat => cat).Where(cat => cat.idCategory == Convert.ToInt32(Request.QueryString["id"])).FirstOrDefault();
        }
        category.TenCate = txtTenCate.Text.Trim();
        category.TenCate_E = AllCode.Utils.ConvertToUnSign(txtTenCate.Text.Trim().ToString());
        category.ThuTu = Convert.ToInt32(txtThuTu.Text);
        //category.AnHien = chkAnHien.Checked;


        if (Request.QueryString["action"] == "add")
        {
            _db8.Categories.InsertOnSubmit(category);
        }

        _db8.SubmitChanges();

        Response.Redirect("category.aspx");
    }
}